// pages/activity/activity_goods/activity_goods.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sonGroupList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.group_id = options.group_id;
    var title = options.title;
    this.goods_show_type = options.type;
    this.songroupList();
    this.getGoodsOptions();

    //获取我的用户信息
    this.getMyInfo();

    //设置标题
    wx.setNavigationBarTitle({
      title: title,
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    var path = '/pages/homepage/homepage';
    return {
      title: '【' + this.myinfo.user_name + '】，该商品用星星减免超级优惠，全场包邮>>',
      path: path,
      success: () => {
      }
    }
  },

  /**
   * 获取我的用户信息
   */
  getMyInfo: function () {
    app.getUserInfo((res) => {
      this.myinfo = res
    })
  },

  /**
   * 免费兑换--子分组
   */
  songroupList: function() {
    app.Ajax({
      url: '/api/index.php?app=category&act=group',
      data: {
        group_id: this.group_id,
      },
      success: (res) => {
        this.setData({
          sonGroupList: res
        })
      }
    })
  },

  /**
   * 免费兑换--商品
   */
  getGoodsOptions: function() {
    var goodsOption = {
      list_id: 'free_goods',
      url: '/api/index.php?app=category&act=group_goods',
      data: {
        group_id: this.group_id
      }
    }
    this.setData({
      goodsOption: goodsOption,
      pageHeight: app.globalData.pageHeight,
      goods_show_type: this.goods_show_type
    })
  },

  /**
   * 加载更多商品
   */
  loadMoreGoods: function(e) {
    this.setData({
      goodsList: e.detail.data,
    })
  },

  /**
   * 进入子分组
   */
  sonGroupClick: function(e) {
    var id = e.detail.id;
    wx.navigateTo({
      url: '../../goods/goods_list/goods_list?goods_type=1&id=' + id,
    })
  },

  /**
   * 查看商品信息
   */
  lookGoodsInfo: function(e) {
    var id = e.detail.id;
    wx.navigateTo({
      url: '../../goods_detail/goods_detail?group_id=' + this.group_id + '&goods_id=' + id,
    })
  }

})